package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/conditionSearch")
    @ApiOperation("完成分页查询")
    public Result<PageResult> orderList(OrdersPageQueryDTO orderPageQueryDTO) {
        PageResult pageResult = orderService.list(orderPageQueryDTO);
        return Result.success(pageResult);
    }

    @PutMapping("/confirm")
    public Result confirmOrder(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        Long id = ordersConfirmDTO.getId();
        orderService.setConfirmStatus(id);
        return Result.success();
    }

    @GetMapping("/details/{id}")
    public Result<Orders> orderDetails(@PathVariable Long id) {
        Orders orders = orderService.orderById(id);
        return Result.success(orders);
    }

    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statisticsVO() {
        OrderStatisticsVO orderStatisticsVO = orderService.totalStatis();
        return Result.success(orderStatisticsVO);
    }

    @PutMapping("/rejection")
    public Result rejectionStatus(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        orderService.rejectionStatus(ordersRejectionDTO);
        return Result.success();
    }

    @PutMapping("/cancel")
    public Result cancelStatus(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        orderService.cancelStatus(ordersCancelDTO);
        return Result.success();
    }
    @PutMapping("/delivery/{id}")
    public Result deliveryOrder(@PathVariable Long id){
        orderService.deliveryOrder(id);
        return Result.success();
    }

    @PutMapping("/complete/{id}")
    public Result completeOrder(@PathVariable Long id){
        orderService.completeOrder(id);
        return Result.success();
    }


}
